<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- <script>
      var arr = [5, 4, 3, 2, 1];
      function bubbleSort() {
        if (!Array.isArray(arr)) {
          return;
        }
        if (arr.length === 0) {
          return;
        }

        for (var i = 0; i < arr.length - 1; i++) {
          for (var j = 0; j < arr.length - 1; j++) {
            if (arr[j] > arr[j + 1]) {
              [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
            }
          }
        }
        return arr;
      }

      console.log(bubbleSort(arr));
    </script> -->

    <!-- <script>
      var arr = [9, 2, 8, 4, 6];
      function bulble(arr) {
        if (!Array.isArray(arr)) {
          return;
        }
        if (arr.length == 0) {
          return;
        }

        for (var i = 0; i < arr.length - 1; i++) {
          for (var j = 0; j < arr.length - 1 - i; j++) {
            if (arr[j] > arr[j + 1]) {
              [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
            }
          }
        }

        return arr;
      }

      console.log(bulble(arr));
    </script> -->

    <!-- <script>
      var arr = [9, 2, 8, 4, 6];
      function bulble(arr) {
        if (!Array.isArray(arr)) {
          return;
        }
        if (arr.length == 0) {
          return;
        }

        for (var i = 0; i < arr.length - 1; i++) {
          var isSort = true;
          for (var j = 0; j < arr.length - 1 - i; j++) {
            if (arr[j] > arr[j + 1]) {
              [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
              isSort = false;
            }
          }

          if (isSort) {
            return arr;
          }
        }
      }

      console.log(bulble(arr));
    </script> -->

    <script>
      var arr = [5, 4, 0, 2, 1];
      function quickSort(arr) {
        if (arr.length < 1) {
          return arr;
        }
        var left = [];
        var right = [];
        var pivot = arr[Math.floor(arr.length / 2)];
        for (var i = 0; i < arr.length; i++) {
          if (arr[i] < pivot) left.push(arr[i]);
          if (arr[i] > pivot) right.push(arr[i]);
        }
        return quickSort(left).concat(pivot, quickSort(right));
      }

      console.log(quickSort(arr));
    </script>
  </body>
</html>
